/*
 * Copyright (C) 2010-2010 MaoJian Wu
 *
 * Author:
 *	MaoJian Wu
 *
 * Source:
 *	
 *
 * This file is a part of zfspear library.
 *
 *
 */

#include "presence.h"
#include "xmpp_uri.h"
#include "status.h"
Presence::Presence() :
        Stanzas("presence",XmppUri::CLIENT) {
}
void Presence::SetShow(ShowType show) {
    QString strShow;
    switch (show) {
    case Presence::ShowType::Offline: {
       strShow="Offline";
    }
    case Presence::ShowType::Online: {
       strShow="Online";
    }
    case Presence::ShowType::Away: {
       strShow="Away";
    }
    case Presence::ShowType::XA: {
       strShow="XA";
    }
    case Presence::ShowType::DND: {
       strShow="DND";
    }
    default: {
       strShow="NONE";
    }
    this->SetTag("show",strShow);
}
}

QString Presence::Show() {
    return this->GetTag("show");
}

void Presence::SetStatus(QList<Status*> statusList) {
    QListIterator<Status*> iterator(statusList);
    while (iterator.hasNext()) {
        Status *status=iterator.next();
        this->AppendChild(status);
    }

}
void Presence::SetStatus(QList<QString> statusList) {
    QListIterator<QString> iterator(statusList);
    while (iterator.hasNext()) {
        QString status=iterator.next();
        this->AddTag("status",status);
    }

}
void Presence::SetStatus(const QString& status) {
   this->SetTag("status",status);
}

QString Presence::GetStatus() {
  return this->GetTag("status");
}

QList<Status*> Presence::StatusList() {
    QList<Status*> StatusList;
    QListIterator<XmppElement*> iterator(this->ChildElements());
    while (iterator.hasNext()) {
        //Status* status=iterator.next();
        //this->AppendChild(status);
    }
    return StatusList;
}

void Presence::SetPriority(int priority) {
    QString strPriority;
    this->SetTag("priority",strPriority.setNum(priority));
}

int Presence::Priority() {
    QString  strPriority=this->GetTag("priority");
    bool ok;
    int priority = strPriority.toInt(&ok, 10);
    if (ok) {
        return priority;
    } else {
        return 0;
    }
}


